{extend name="../public/header" /}
{block name="body"}
<style>
.grid-demo{text-align: center;font-size: 12px;line-height: 24px;margin: 5px 0;}
.grid-demo a{padding: 5px;border: #DBDCDD 1px solid;}
</style>
<body>
{include file="../public/common" /}
<fieldset class="layui-elem-field site-demo-button" style="padding:10px;">
	<div class="layui-row">
		<!--  -->
		<form id="form1" class="layui-form layui-form-pane" action="{:url('edit')}">
			<section class="panel panel-padding">
				<div class="layui-form-item">
					<label class="layui-form-label">归属</label>
					<div class="layui-input-inline">
						<select name="mqy">
							<option value="0">请选择</option>
							{volist name='list' id='vo' key='k'}
							<option value="{$vo.qyid}" {if condition="$vo.qyid eq $info.mqy"}selected{/if}>{$vo.qyname}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-input-inline">
						<input type="text" name="mname" value="{$info.mname|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">介绍</label>
					<div class="layui-input-inline">
						<textarea name="midinfo" placeholder="请输入介绍" class="layui-textarea">{$info.midinfo|default=''}</textarea>
					</div>
				</div>
				<!-- / -->
				<fieldset class="layui-elem-field" style="width: 500px;">
					<legend>交通布局</legend>
					<div class="layui-field-box">
						<div class="layui-row">
							<div class="layui-col-xs4 layui-col-sm4 layui-col-md4 layui-col-xs-offset4 layui-col-sm-offset4 layui-col-md-offset4">
								<div class="grid-demo">
									<input type="hidden" id="mup" name="mup" value="{$info.mup|default='0'}" class="layui-input">
									<a href="javascript:;" class="ajax-edit" data-url="{:url('traffic',['id'=>$info.mup])}" data-title="↑" data-field="mup">↑{$info.mup_name}</a>
								</div>
							</div>
						</div>
						<div class="layui-row">
							<div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
								<div class="grid-demo">
									<input type="hidden" id="mleft" name="mleft" value="{$info.mleft|default='0'}" class="layui-input">
									<a href="javascript:;" class="ajax-edit" data-url="{:url('traffic',['id'=>$info.mleft])}" data-title="←" data-field="mleft">←{$info.mleft_name}</a>
								</div>
							</div>
							<div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
								<div class="grid-demo">
									<a href="javascript:;">{$info.mname}</a>
								</div>
							</div>
							<div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
								<div class="grid-demo">
									<input type="hidden" id="mright" name="mright" value="{$info.mright|default='0'}" class="layui-input">
									<a href="javascript:;" class="ajax-edit" data-url="{:url('traffic',['id'=>$info.mright])}" data-title="→" data-field="mright">→{$info.mright_name}</a>
								</div>
							</div>
						</div>
						<div class="layui-row">
							<div class="layui-col-xs4 layui-col-sm4 layui-col-md4 layui-col-xs-offset4 layui-col-sm-offset4 layui-col-md-offset4">
								<div class="grid-demo">
									<input type="hidden" id="mdown" name="mdown" value="{$info.mdown|default='0'}" class="layui-input">
									<a href="javascript:;" class="ajax-edit" data-url="{:url('traffic',['id'=>$info.mdown])}" data-title="↓" data-field="mdown">↓{$info.mdown_name}</a>
								</div>
							</div>
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>怪物配置</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="mgid">
							<div class="layui-form-item">
								<label class="layui-form-label">怪物</label>
								<button class="layui-btn ajax-getGw" data-url="{:url('getGwList')}" type="button">新增</button>
							</div>
							{foreach name='info.mgid_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="mgid[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="mgid[{$key}][name]" value="{$vo.name}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">数量</label>
								<div class="layui-input-inline">
									<input name="mgid[{$key}][num]" value="{$vo.num}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNumGw(this)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>npc配置</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="mnpc">
							<div class="layui-form-item">
								<label class="layui-form-label">npc</label>
								<button class="layui-btn ajax-getNpc" data-url="{:url('getNpcList')}" type="button">新增</button>
							</div>
							{foreach name='info.mnpc_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="mnpc[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="mnpc[{$key}][name]" value="{$vo.name}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNumNpc(this)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<div class="layui-form-item">
					<label class="layui-form-label">领主</label>
					<div class="layui-input-inline">
						<select name="midboss">
							<option value="0">请选择</option>
							{volist name='$listBoss' id='vo' key='k'}
							<option value="{$vo.bossid}" {if condition="$vo.bossid eq $info.midboss"}selected{/if}>[lv:{$vo.bosslv}]{$vo.bossname}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">刷新间隔</label>
					<div class="layui-input-inline">
						<input type="text" name="ms" value="{$info.ms}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">允许PK</label>
					<div class="layui-input-inline">
						<input type="radio" name="ispvp" {eq name="info.ispvp" value="0"}checked{/eq} title="否" value="0" checked />
						<input type="radio" name="ispvp" {eq name="info.ispvp" value="1"}checked{/eq} title="是" value="1" />
					</div>
				</div>
				<!-- / -->

				<div class="layui-input-block">
					<input type="hidden" name="mid" type="hidden" value="{$info.mid|default=''}">
					<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</section>
		</form>
		<!--  -->
	</div>
</fieldset>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','form','laydate','upload','element'], function(){
	var $ = layui.jquery
	,laydate = layui.laydate
	,upload = layui.upload
	,element = layui.element
	,form = layui.form;

	$('.ajax-edit').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var title = obj.data('title');
		var field = obj.data('field');
		layer.open({
			type: 2,
			title: '向' + title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['400px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];

				var obja = $(n).contents().find("input[name='id']");
				var objb = $(n).contents().find("select[name='mid'] option:selected");
				var id = $(obja).val();
				var mid = $(objb).val();
				var mname = $(objb).data('title');

				console.log('mid',mid);
				console.log('mname',mname);
				console.log('field',field);

				obj.html(title + mname);
				$('#'+field).val(mid);

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		});
	});

	$('.ajax-getGw').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var title = obj.data('title');

		layer.open({
			type: 2,
			title: title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['500px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];
				var objb = $(n).contents().find("select[name='monster_id'] option:selected");
				var monster_id = $(objb).val();
				var text = $(objb).text();

				console.log('id',monster_id);
				console.log('name',text);

				addGw(monster_id,text);

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		});
	});

	$('.ajax-getNpc').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var title = obj.data('title');

		layer.open({
			type: 2,
			title: title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['400px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];
				var objb = $(n).contents().find("select[name='npc_id'] option:selected");
				var npc_id = $(objb).val();
				var text = $(objb).text();

				console.log('id',npc_id);
				console.log('name',text);

				addNpc(npc_id,text);

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		})
	});

	form.render();
});
</script>
<script>
	var num_mgid = "{$num_mgid|default='1'}";
	var num_mnpc = "{$num_mnpc|default='1'}";

	layui.use(['jquery','form'], function(){
		var $ = layui.jquery
			,form = layui.form;

		window.addGw = function(id,name) {
			console.log('num_mgid',num_mgid);
			$("#mgid").append(
					"<div class='layui-form-item'>" +
					"<label class='layui-form-label'>ID</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='mgid["+num_mgid+"][id]' value='"+id+"' placeholder='请输入' class='layui-input '>" +
					"</div>" +
					"<label class='layui-form-label'>名称</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='mgid["+num_mgid+"][name]' value='"+name+"' placeholder='请输入' class='layui-input '>" +
					"</div>" +
					"<label class='layui-form-label'>数量</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='mgid["+num_mgid+"][num]' value='1' placeholder='请输入' class='layui-input'>" +
					"</div>" +
					"<button class='layui-btn layui-btn-danger'  onclick='delNumGw(this)' type='button'>-</button>" +
					"</div>");
			num_mgid++;
		}

		window.addNpc = function(id,name) {
			console.log('num_mnpc',num_mnpc);
			$("#mnpc").append(
					"<div class='layui-form-item'>" +
					"<label class='layui-form-label'>ID</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='mnpc["+num_mnpc+"][id]' value='"+id+"' placeholder='请输入' class='layui-input '>" +
					"</div>" +
					"<label class='layui-form-label'>名称</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='mnpc["+num_mnpc+"][name]' value='"+name+"' placeholder='请输入' class='layui-input '>" +
					"</div>" +
					"<button class='layui-btn layui-btn-danger'  onclick='delNumNpc(this)' type='button'>-</button>" +
					"</div>");
			num_mnpc++;
		}
	});

	function delNumGw(obj) {
		var $= layui.jquery;
		$(obj).parent().remove();
		num_mgid--;
	}
	function delNumNpc(obj) {
		var $= layui.jquery;
		$(obj).parent().remove();
		num_mnpc--;
	}
</script>
{/block}